package reflecttest;

import java.lang.reflect.Field;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
import java.util.Map;

public class GenericTest {
    private Map<String,Integer>score;
    public static void main(String[] args) throws NoSuchFieldException {
        Class<GenericTest> clazz = GenericTest.class;
        Field f = clazz.getDeclaredField("score");
        Class<?> a = f.getType();
        System.out.println("socre type is-->"+a);
        Type gType = f.getGenericType();
        System.out.println("socre GenericType is-->"+gType);
        if (gType instanceof ParameterizedType){
            ParameterizedType pType = (ParameterizedType)gType;
            //获取原始类型
            Type rType = pType.getRawType();
            System.out.println("socre RawType is-->"+rType);
            Type[] tArgs = pType.getActualTypeArguments();
            for (int i = 0; i < tArgs.length; i++) {
                System.out.println("Args["+i+"]-->"+tArgs[i]);
            }
        }else {
            System.out.println("Error getting ParameterizedType");
        }
    }
}
